import HfSuperForm from "@/components/HfSuperForm/index.vue";
import HfTable from "@/components/HfTable/index.vue";

const typeKeytoInterface={
  cTable:{props:'ITableP',emits:"ITableE",ex:'ITableEX'},
  pageForm :{props:'ISupP',emits:"ISupE",ex:'ISupEX'},
  searchForm:{props:'ISusP',emits:"ISusE",ex:'ISusPEX'},
  diologForm:{props:'ISudP',emits:"ISudE",ex:'ISudPEX'},
}
function templateFn(data: IStdOContainerRender) {
 if(data.key=='cTable') ` <HfTable v-bind="${data.highEdit.ref}Props" ref="${data.highEdit.ref}Ref" v-on="${data.highEdit.ref}Emits"/>`
 return ` <HfSuperForm v-bind="${data.highEdit.ref}Props" ref="${data.highEdit.ref}Ref" v-on="${data.highEdit.ref}Emits"/>`
}
function scriptFn(data: IStdOContainerRender,otherMethods:string[]) {
  if (data.type !== "container") return;
  let datad:string=`  let ${data.highEdit.ref}Ref = ref<${typeKeytoInterface[data.key].ex}>();
  let ${data.highEdit.ref}Props = ref<${typeKeytoInterface[data.key].props}>( ${JSON.stringify(data.props)})
  let ${data.highEdit.ref}Emits: ${typeKeytoInterface[data.key].emits} = {`
  if(data.key=='cTable')  datad+`
    ${data.highEdit.emitToOpen? `({ fn }) => pageEmit.emitToOpen({ dioRef: ${data.highEdit.emitToOpen}, row })`:''},`;
  datad+`
  emitChangeProps: (objd: ISuECommonChangePropsEmitArgue) => pageEmit.emitChangeProps(objd, ${data.highEdit.ref}Props.value),
  `
if(data.key=='searchForm')  datad+`
  ${data.highEdit.emitGetListFn? `({ fn }) => pageEmit.emitGetListFn({ tableRef: ${data.highEdit.emitGetListFn}, fn })`:''},
  ${data.highEdit.emitToOpen? `({ fn }) => pageEmit.emitToOpen({ dioRef: ${data.highEdit.emitToOpen}, null })`:''},`;
if(data.key=='diologForm')  `
  ${data.highEdit.emitGetListFn? `({ fn }) => pageEmit.emitGetListFn({ tableRef: ${data.highEdit.emitGetListFn}, fn })`:''},`;
if(otherMethods){
  otherMethods.map((item)=>{
    datad+','+item
  })
}
  datad+`
};`
}
const headerOpt= {
  template: (data: IStdOPageFormRender) => templateFn(data),
  script: (data: IStdOPageFormRender,otherMethods:string[]) => scriptFn(data,otherMethods),
}
export default function initContainer(registerConfig: registerConfigFnType<IStdOContainerDrag>) {
  registerConfig.register({
    key: "searchForm",
    type: "container",
    typed: "containerForm",
    leftOpt: { label: "搜索容器", preview: <HfSuperForm formType="searchForm" formOpt={{ items: {} }} /> },
    middleOpt: {
      // @ts-ignore formType="searchForm" formOpt={{items:{}}}
      render: <HfSuperForm />,
      props: { formOpt: {}, formType: "searchForm" },
      highEdit: { ref: "searchForm" }
    },
    rightOpt: {
      settingRender: [
        { type: "text", key: "ref", label: "ref", editType: "high", tip: "自身Ref值" },
        { key: "emitToOpen", type: "text", label: "emitToOpen", tip: "新增时所需打开的弹窗Ref值-一般初始值diologFormRef", editType: "high" },
        { key: "emitGetListFn", type: "text", label: "emitGetListFn", tip: "查询时所需搜索的表格Ref值-一般初始值tableRef", editType: "high" },
        { key: "noAdd", propKey: ["superFormOpt"], type: "radio", label: "noAdd", tip: "不展示新增按钮", editType: "normalProp" },
        { key: "addBtnText", propKey: ["superFormOpt"], type: "text", label: "addBtnText", tip: "新增按钮的文字展示", editType: "prop" },
        { key: "notdialogAdd", propKey: ["superFormOpt"], type: "radio", label: "notdialogAdd", tip: "点击新增不打开弹窗", editType: "prop" },
        { key: "newRoute", propKey: ["superFormOpt"], type: "text", label: "newRoute", tip: "新增按钮跳转页面新增时所需的路径", editType: "prop" },
        { key: "noReset", propKey: ["superFormOpt"], type: "radio", label: "noReset", tip: "不展示重置按钮", editType: "prop" }
      ]
    },
    headerOpt
  });
  registerConfig.register({
    key: "diologForm",
    type: "container",
    typed: "containerForm",
    leftOpt: { label: "弹窗新增容器", preview: <div style={{ fontSize: "12px" }}>弹窗新增容器</div> },
    middleOpt: {
      // @ts-ignore formType: "diologForm", formOpt={{items:{}}}
      render: <HfSuperForm />,
      props: { formType: "diologForm", formOpt: {}, superFormOpt: { title: "新增/编辑" } },
      highEdit: { ref: "diologForm" },
      otherProps: { superFormOpt: { open: true } }
    },
    rightOpt: {
      settingRender: [
        { key: "saveUrl", type: "text", label: "saveUrl", propKey: ["formOpt"], editType: "normalProp", tip: "保存时的接口" },
        { key: "ref", type: "text", label: "ref", editType: "high", tip: "自身Ref值" },
        { key: "emitGetListFn", type: "text", label: "emitGetListFn", tip: "新增后所需搜索的表格Ref值-一般初始值tableRef", editType: "high" },
        { key: "searchFormKey", type: "text", label: "searchFormKey", tip: "新增后所需搜索的表单Ref值-一般初始值searchFormRef", editType: "high" },
        { key: "title", propKey: ["superFormOpt"], type: "text", label: "title", tip: "弹窗标题", editType: "normalProp" },
        { key: "width", propKey: ["superFormOpt"], type: "text", label: "width", tip: "弹窗宽度", editType: "prop" },
        { key: "noSubmit", propKey: ["superFormOpt"], type: "radio", label: "noSubmit", tip: "没有确认按钮", editType: "prop" },
        { key: "style", propKey: ["superFormOpt"], type: "text", label: "style", tip: "弹窗样式", editType: "prop" },
        { key: "top", propKey: ["superFormOpt"], type: "text", label: "top", tip: "弹窗离顶部多少距离", editType: "prop" },
        { key: "noFooter", propKey: ["superFormOpt"], type: "radio", label: "noFooter", tip: "没有底部", editType: "prop" },
        { key: "notSaveAfter", propKey: ["superFormOpt"], type: "radio", label: "notSaveAfter", tip: "新增后不需要刷新表格", editType: "prop" },
        { key: "open", propKey: ["superFormOpt"], type: "radio", label: "open", tip: "弹窗是否打开", editType: "prop" }
        // { key: "otherParams", propKey: ["formOpt"], type: "radio", label: "otherParams", tip: "新增时需要携带的其他参数", editType: "prop" },
      ]
    },
    headerOpt
  });
  registerConfig.register({
    key: "pageForm",
    typed: "containerForm",
    type: "container",
    leftOpt: {
      label: "新增页面容器",
      preview: <HfSuperForm formType="pageForm" formOpt={{ items: {} }} />
    },
    middleOpt: {
      // @ts-ignore formType="pageForm" formOpt={{items:{}}}
      render: <HfSuperForm />,
      props: { formType: "pageForm", formOpt: {}, superFormOpt: {} },
      highEdit: { ref: "pageForm" }
    },
    rightOpt: {
      settingRender: [
        { type: "text", key: "ref", label: "ref", editType: "high", tip: "自身Ref值" },
        { type: "text", key: "saveUrl", propKey: ["formOpt"], label: "saveUrl", editType: "normalProp", tip: "保存时的接口" },
        { propKey: ["superFormOpt"], key: "detailUrl", type: "text", label: "detailUrl", tip: "获取详情的接口", editType: "normalProp" },
        { propKey: ["superFormOpt"], key: "saveTxt", type: "text", label: "saveTxt", tip: "新增按钮的展示文字", editType: "normalProp" }
        // { key: "otherParams", propKey: ["formOpt"], type: "radio", label: "otherParams", tip: "新增时需要携带的其他参数", editType: "prop" },
      ]
    },
    headerOpt
  });
  registerConfig.register({
    key: "cTable",
    type: "container",
    typed: "containerTable",
    leftOpt: { label: "表格容器", preview: <HfTable tableOpt={{ list: { url: "" }, columns: [] }} /> },
    middleOpt: {
      // @ts-ignore tableOpt={{ list: { url: "" }, columns: [{ label: "1" }] }}
      render: <HfTable  />,
      highEdit: { ref: "cTable" },
      props: { tableOpt: { list: {} } },
    },
    rightOpt: {
      settingRender: [
        { type: "text", key: "url", propKey: ["tableOpt", "delete"], tip: "删除按钮对应的接口", label: "delete-url", editType: "normalProp" },
        { type: "text", propKey: ["tableOpt", "list"], key: "url", tip: "获取数据的接口", label: "url", editType: "normalProp" },
        { type: "text", propKey: ["tableOpt", "list"], key: "params", tip: "获取数据的接口尾缀", label: "params", editType: "prop" },
        { type: "radio", propKey: ["tableOpt"], key: "summary", tip: "是否有合计", label: "summary", editType: "prop" },
        { type: "text", key: "hasChildren", propKey: ["tableOpt", "treeProps"], tip: "树形时当前列是否有儿子的字段判断", label: "hasChildren", editType: "prop" },
        { type: "text", key: "children", propKey: ["tableOpt", "treeProps"], tip: "树形时当前列 儿子的字段", label: "children", editType: "prop" },
        { type: "text", key: "rowKey", propKey: ["tableOpt"], tip: "row中包含children字段去展示树类型结构时所需 默认值是id", label: "rowKey", editType: "prop" },
        { type: "radio", key: "selection", propKey: ["tableOpt"], tip: "是否有勾选项", label: "selection", editType: "prop" },
        { type: "number", key: "btnWidth", propKey: ["tableOpt"], tip: "操作栏宽度", label: "btnWidth", editType: "prop" },
        { type: "radio", key: "noBtn", propKey: ["tableOpt"], tip: "是否隐藏操作栏", label: "noBtn", editType: "normalProp" },
        { type: "radio", key: "hideEdit", propKey: ["tableOpt"], tip: "是否隐藏编辑按钮", label: "hideEdit", editType: "normalProp" },
        { type: "radio", key: "expand", propKey: ["tableOpt"], tip: "列表是否可展开", label: "expand", editType: "prop" },
        { type: "radio", key: "noPage", propKey: ["tableOpt"], tip: "没有pagination区域", label: "noPage", editType: "normalProp" },
        { type: "radio", key: "simplePage", propKey: ["tableOpt"], tip: "自定义pagination区域内容", label: "simplePage", editType: "prop" },
        { type: "text", key: "pageSizes", propKey: ["tableOpt"], tip: "表格查询条数配置", label: "pageSizes", editType: "prop" },
        { type: "number", key: "pageSize", propKey: ["tableOpt"], tip: "默认查询条数", label: "pageSize", editType: "prop" },
        { type: "radio", key: "jumpAdd", propKey: ["tableOpt"], tip: "编辑是否跳转新页面", label: "jumpAdd", editType: "prop" },
        { type: "text", key: "detailPage", propKey: ["tableOpt"], tip: "编辑时跳转到新页面的新页面路径", label: "detailPage", editType: "prop" },
        { type: "radio", key: "selectionId", propKey: ["tableOpt"], tip: "表格勾选时勾选数据是否只放入id", label: "selectionId", editType: "prop" },
        { type: "text", key: "beforeGetList", propKey: ["tableOpt"], tip: "getListFn发起请求前的数据处理 发起emit('emitBeforeGetList', obj, pageSize);", label: "beforeGetList", editType: "prop" },
        { type: "radio", key: "emitAfterGetData", propKey: ["tableOpt"], tip: "getListFn后是否发起emit('emitAfterGetData', tableData.value)进行返回值的处理", label: "emitAfterGetData", editType: "prop" },
        { type: "radio", key: "noData", propKey: ["tableOpt"], tip: "加载后不发起请求", label: "noData", editType: "normalProp" },
        { type: "radio", key: "deleteTxt", propKey: ["tableOpt", "delete"], tip: "删除按钮的文字", label: "delete-deleteTxt", editType: "prop" },
        { type: "text", key: "emitDeleteAfter", propKey: ["tableOpt", "delete"], tip: "删除后需要emit('emitDeleteAfter')", label: "delete-emitDeleteAfter", editType: "prop" },
        {
          type: "valueKeyList",
          propKey: ["tableOpt", "release"],
          key: "releaseItem",
          tip: "启用禁用对应的相关信息，有默认值 {state: true, changeMsg: '下架成功', showMsg: '上架', btnType:'primary' },{ state: false, changeMsg: '上架成功', showMsg: '下架', btnType: 'danger' }",
          label: "release-releaseItem",
          editType: "prop",
          valueKeyList: [
            { type: "text", tip: "表格里的值", key: "state", propKey: ["tableOpt", "release", "releaseItem"], label: "state", editType: "prop" },
            { type: "text", tip: "操作栏按钮点击后展示的提示信息文案", key: "changeMsg", propKey: ["tableOpt", "release", "releaseItem"], label: "changeMsg", editType: "prop" },
            { type: "text", tip: "操作栏的按钮文案", key: "showMsg", propKey: ["tableOpt", "release", "releaseItem"], label: "showMsg", editType: "prop" },
            { type: "text", tip: "操作栏按钮的类型", key: "btnType", propKey: ["tableOpt", "release", "releaseItem"], label: "btnType", editType: "prop" }
          ]
        },
        { type: "text", key: "props", propKey: ["tableOpt", "release"], tip: "表格里的字段", label: "props", editType: "prop" },
        { type: "text", key: "url", propKey: ["tableOpt", "release"], tip: "启用禁用的接口", label: "url", editType: "prop" },
        { key: "emitToOpen", type: "text", label: "emitToOpen", tip: "编辑时所需打开的弹窗Ref值-一般初始值diologFormRef", editType: "high" },
        { type: "text", key: "ref", tip: "", label: "自身Ref值", editType: "high" }
      ]
    },
    headerOpt
  });
}
